package com.lagou.anno;

import com.lagou.config.RoutingDataSourceUtil;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

/**
 * 通过扫描RoutingWith注解中的值
 * 在切面中执行theadLocal的set方法，将key存入
 */
@Aspect
@Component
public class RoutingAspect {
    @Around("@annotation(with)")
    public Object routingWithDatasource(ProceedingJoinPoint joinPoint, RoutingWith with) throws Throwable {
        String key = with.value();
        RoutingDataSourceUtil routingDataSourceUtil = new RoutingDataSourceUtil(key);
        return joinPoint.proceed();
    }
}
